#pragma once

#include <core/core.h>
#include <core/string.h>

namespace Core
{
    class CORE_API Mutex
    {
    public:
        virtual bool tryLock() { return false; }
        virtual bool lock() { return false; }
        virtual void unlock() {}
    };

    class CORE_API ThreadMutex : public Mutex
    {
        String m_name;
        HANDLE m_mutex;
    public:
        ThreadMutex(const String& name);
        ~ThreadMutex();

        bool tryLock();
        bool lock(ULong ms);
        bool lock();
        void unlock();
    };

    class MutexLocker
    {
        Mutex* m_mutex;
    public:
        MutexLocker(Mutex& mutex) : m_mutex(&mutex)
        {
            m_mutex->lock();
        }

        ~MutexLocker()
        {
            m_mutex->unlock();
        }
    };
}